<template>
  <div class="el-toolbar">
    <template v-for="k in keys">
      <template v-for="item in privileges">
        <template v-if="item.path === k">
          <el-button @click="emitEventHandler(item.path)" type="info" plain :icon="`el-icon-`+item.icon" size="small"
                     :key="k + item.path">{{ item.menuName }}
          </el-button>
        </template>
      </template>
    </template>
    <template v-for="k in keys">
      <template v-if="k === 'back'">
        <el-button @click="emitEventHandler('back')" type="primary" icon="el-icon-back" plain size="mini" :key="k">返回
        </el-button>
      </template>
    </template>
  </div>
</template>

<script>
export default {
  name: 'toolbar',
  props: {
    privileges: {
      type: Array,
      default: () => []
    },
    keys: {
      type: Array,
      default: () => []
    },
    align: {
      type: String,
      default: () => {
        return 'left'
      }
    }
  },
  data() {
    return {}
  },
  methods: {
    emitEventHandler(key) {
      this.$emit('on-' + key)
    }
  }
}
</script>

<style lang="stylus" scoped>

.el-toolbar
  margin 20px 0

  button:nth-child(n+2)
    margin-left 5px
</style>
